<%@ LANGUAGE="VBSCRIPT" %>
<% Option Explicit %>
<!--#include file="includes/cb_adovbs_sys.inc"-->
<!--#include file="includes/header_sys.asp"-->
<!--#include file="includes/authority_sys.asp" -->
<!--#include file="includes/generally_sys.asp"-->
<!--#include file="includes/translate.asp"-->
<!--#include file="includes/email_config_.asp"-->
<!--#include file="includes/email_check.asp"-->
<%
On Error Resume Next
Dim objConn, sql, resp, rst, count_emails, captcha, email, tmp_pw, user_id, old_pw, email_text, first_name, str_user_id, lng_k_email_inquiry, last_name
Dim gInquiry, email2, redirect_email, msg17, msg16

'Sprache -----------------------------------------------------------------
Dim i_lng
i_lng = Request("lng")
If IsEmpty(i_lng) or IsNull(i_lng) or i_lng = 0 Then
    If IsEmpty(Session("ses_i_language")) Then
        i_lng = 1
    Else
        i_lng = Session("ses_i_language")
    End If
end if
Session("ses_i_language")=i_lng'0=keine auswahl 1=german 2=english
'--------------------------------------------------------------------------

'sprache
Dim lng_id
lng_id = i_lng


Set objConn = Server.CreateObject("ADODB.Connection")
objConn.open strComplete_sys
captcha = Replace(Request("captcha"), "'", "''")
email = Replace(Request("email"), "'", "''")
gInquiry = Request("inquiry")
email2 = Replace(Request("email2"), "'", "''")
user_id = Replace(Request("user_id"), "'", "''")

Set rst = Server.CreateObject("ADODB.Recordset")

sql = "SELECT * FROM tbl_0904_pw_email WHERE active = 1 LIMIT 1"
rst.Open sql, objConn
If Not rst.EOF Then
    redirect_email = rst.Fields("email")
end if
rst.Close

if  gInquiry <> "" Then
	tmp_pw = fc_str_pw()
	sql = "SELECT a.*, b.str_User_First_Name, b.str_User_Last_Name " &_
		  "FROM tbl_0903_pw_inquiry a " &_
		  "LEFT JOIN tbl_0501_user b ON b.str_User_id = a.str_User_id " &_
		  "WHERE a.lng_k_email_inquiry = '" & gInquiry & "' " &_
		  "AND a.str_User_id = '" & user_id & "' " &_
		  "LIMIT 1"
	rst.Open sql, objConn
    
    str_user_id = rst.Fields("str_User_id")
    first_name = rst.Fields("str_User_First_Name")
    last_name = rst.Fields("str_User_Last_Name")
    If redirect_email = "user" Then
        email = rst.Fields("str_email")
    Else
        email = redirect_email
    End If
	If Not rst.EOF Then
        email_text = fc_value_string(lng_id, "var_email_template_lost_pw_01")
		email_text = Replace(email_text, "[FirstName]", first_name)
		email_text = Replace(email_text, "[LastName]", last_name)
		email_text = Replace(email_text, "[existing ID]", str_user_id)
		email_text = Replace(email_text, "[temporary string]", tmp_pw)
		email_text = Replace(email_text, "[000.00.000.000]", Request.ServerVariables("remote_addr"))
		call sendmail_now(email, "support@growmetry.com", fc_value_string(lng_id, "var_lost_pw_48"), email_text)
		
		sql = "UPDATE tbl_0903_pw_inquiry SET str_temp_pw = '" & tmp_pw & "'" &_
			  "WHERE lng_k_email_inquiry = '" & gInquiry & "' " &_
			  "AND str_User_id = '" & user_id & "' "
		objConn.Execute sql
	end if
    msg17 = Replace(fc_value_string(lng_id, "var_lost_pw_17"), "'", "\'")
    msg17 = Replace(msg17, vbNewLine, "")
    msg17 = Replace(msg17, "[user-ID]", user_id)
    msg17 = Replace(msg17, "[email]", rst.Fields("str_email"))
	resp = "{status: 'OK', msg: '"& msg17 &"'}"
Else
    if IsEmpty(Session("ASPCAPTCHA")) then
        resp = "{status: 'action', msg: '"&Replace(fc_value_string(lng_id, "var_lost_pw_53"), "'", "\'")&"', do: 'reloadCaptcha'}"
	elseIf captcha <> Session("ASPCAPTCHA") then
		resp = "{status: 'error', msg: '"&Replace(fc_value_string(lng_id, "var_lost_pw_52"), "'", "\'")&"'}"
	else
		lng_k_email_inquiry = fc_i_emailcheck(email)
		sql = "select count(1) c from tbl_0903_pw_inquiry where lng_k_email_inquiry = '" & lng_k_email_inquiry & "'"
		rst.Open sql, objConn
		If Not rst.EOF Then
	    	count_emails = rst.Fields("c")
		end if
        
        msg16 = Replace(fc_value_string(lng_id, "var_lost_pw_16"), "'", "\'")
        msg16 = Replace(msg16, "[email]", email)
        msg16 = Replace(msg16, vbNewLine, "")
        
		if count_emails = "0" then
			resp = "{status: 'OK', msg: '"& msg16 &"'}"
		elseIf count_emails = "1" then
			tmp_pw = fc_str_pw()
			
			sql = "SELECT a.*, b.str_User_First_Name, b.str_User_Last_Name " &_
				  "FROM tbl_0903_pw_inquiry a " &_
				  "LEFT JOIN tbl_0501_user b ON b.str_User_id = a.str_User_id " &_
				  "WHERE lng_k_email_inquiry = '" & lng_k_email_inquiry & "'"
			rst.Close
			rst.Open sql, objConn
			If Not rst.EOF Then
		    	str_user_id = rst.Fields("str_User_id")
		    	first_name = rst.Fields("str_User_First_Name")
		    	last_name = rst.Fields("str_User_Last_Name")
		    	If redirect_email = "user" Then
                    email = rst.Fields("str_email")
                Else
                    email = redirect_email
                End If
                email_text = fc_value_string(lng_id, "var_email_template_lost_pw_01")
				email_text = Replace(email_text, "[FirstName]", first_name)
				email_text = Replace(email_text, "[LastName]", last_name)
				email_text = Replace(email_text, "[existing ID]", str_user_id)
				email_text = Replace(email_text, "[temporary string]", tmp_pw)
				email_text = Replace(email_text, "[000.00.000.000]", Request.ServerVariables("remote_addr"))
				call sendmail_now(email, "support@growmetry.com", fc_value_string(lng_id, "var_lost_pw_48"), email_text)
				
				sql = "UPDATE tbl_0903_pw_inquiry SET str_temp_pw = '" & tmp_pw & "' WHERE lng_k_email_inquiry = '" & lng_k_email_inquiry & "'"
				objConn.Execute sql
				resp = "{status: 'OK', msg: '"& msg16 &"'}"
			else 
				resp = "{status: 'OK', msg: '"& msg16 &"'}"
			end if
			
			
		Else
			resp = "{status: 'OK', count: '" & count_emails & "', email: '"&email&"', inquiry: '" & lng_k_email_inquiry & "'}"
		End If
	End If
End If

If Err.Number <> 0 Then
	resp = "{status: 'error', msg: '500 "&Err.Description&"'}"
	Err.Clear
End If
Response.Write(resp)
%>